﻿Imports Mysoft.Map.Data
Partial Public Class WF_ProcessAnalysis
    Inherits Mysoft.Map.Application.Security.AppPage
    Private _BUGUID As String
    Private _BUName As String
    Private _beginDatetim As String
    Private _endDatetime As String

    Property BUGUID() As String
        Get
            Return _BUGUID
        End Get
        Set(ByVal value As String)
            _BUGUID = value
        End Set
    End Property
    Property BUName() As String
        Get
            Return _BUName
        End Get
        Set(ByVal value As String)
            _BUName = value
        End Set
    End Property
    Property BeginDatetime() As String
        Get
            Return _beginDatetim
        End Get
        Set(ByVal value As String)
            _beginDatetim = value
        End Set
    End Property
    Property EndDatetime() As String
        Get
            Return _endDatetime
        End Get
        Set(ByVal value As String)
            _endDatetime = value
        End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _BUGUID = Session("BUGUID")
        _BUName = Session("BUName")
        _beginDatetim = Date.Now.ToString("yyyy") & "-01-01"
        _endDatetime = Date.Now.ToString("yyyy-MM-dd")

        If (Not ValidateUserInCompany(_BUGUID, Session("userGUID"))) Then
            _BUGUID = String.Empty
            _BUName = String.Empty
        End If

        Dim script As System.Text.StringBuilder = New System.Text.StringBuilder()

        script.AppendLine("<script  language='javascript'>")
        script.AppendFormat("var _BUGUID ='{0}';", BUGUID)
        script.AppendFormat("var _BUName='{0}';", BUName)
        script.AppendFormat("var _BeginDatetime='{0}';", BeginDatetime)
        script.AppendFormat("var _EndDatetime='{0}';", EndDatetime)
        script.Append("</script>")
        ClientScript.RegisterClientScriptBlock(Me.GetType(), "initSearch", script.ToString)
    End Sub
    ''' <summary>
    ''' 校验用户是否属于当前公司(用户是否拥有公司的岗位)
    ''' </summary>
    ''' <param name="companyGUID">公司GUID</param>
    ''' <param name="userGUID">用户GUID</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ValidateUserInCompany(ByVal companyGUID As String, ByVal userGUID As String) As Boolean
        Dim Sql As String = "Select s.CompanyGUID  FROM myStationUser su  Join myStation s ON su.StationGUID = s.StationGUID WHERE su.UserGUID = '" & Session("UserGUID") & "'"
        Dim dt As DataTable = MyDB.GetDataTable(Sql)
        If dt Is Nothing Then
            Return False
        End If
        For Each dr As DataRow In dt.Rows
            If String.Compare(dr("CompanyGUID").ToString, companyGUID, True) = 0 Then
                Return True
            End If
        Next
        Return False
    End Function
End Class